Skip to content

匹配绑定窗口图片7 - MatchWindowsThresholdFromPathAll

函数简介

二值化后匹配所有符合模板图片的坐标,模板通过文件路径指定,返回相对绑定窗口坐标。

接口名称

MatchWindowsThresholdFromPathAll

DLL调用

long MatchWindowsThresholdFromPathAll(long ola, int x1, int y1, int x2, int y2, string colorJson, string templ, double matchVal, double angle, double scale);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
x1整数型查找区域的左上角X坐标
y1整数型查找区域的左上角Y坐标
x2整数型查找区域的右下角X坐标
y2整数型查找区域的右下角Y坐标
colorJson字符串颜色模型配置字符串,格式说明见 颜色模型说明 - ColorModel。JSON格式示例:[{"StartColor":"3278FA","EndColor":"6496FF","Type":0}];简化格式示例:3278FA-000000|6496FF-2020203278FA~6496FFFF0000|00FF00
templ字符串模板图片的路径,支持多个图片,用"|"分隔,如"test.bmp|test2.bmp|test3.bmp"
matchVal双精度浮点数相似度阈值,范围0-1,如0.85表示85%相似度
angle双精度浮点数旋转角度,每次匹配后旋转指定角度继续匹配,角度越小匹配次数越多时间越长,0为不旋转速度最快
scale双精度浮点数窗口缩放比例,默认为1,可通过GetScaleFromWindows接口获取

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 0,0,0,0 表示绑定窗口整个客户区
auto results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1);
if (!results.empty() && results[0].MatchState) {
    int x = results[0].X;
    int y = results[0].Y;
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
var results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, @"[{""StartColor"":""000000"",""EndColor"":""FFFFFF""}]", "img/template.bmp", 0.9, 0, 1);
if (results.Count > 0 && results[0].MatchState)
{
    int x = results[0].X;
    int y = results[0].Y;
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
# 0,0,0,0 表示绑定窗口整个客户区
results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, '[{"StartColor":"000000","EndColor":"FFFFFF"}]', "img/template.bmp", 0.9, 0, 1)
if results and results[0].get("MatchState"):
    x = results[0]["X"]
    y = results[0]["Y"]
java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.MatchResult;
import java.util.List;

OLAPlugServer ola = new OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
List<MatchResult> results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1);
if (results != null && !results.isEmpty() && results.get(0).MatchState) {
    int x = results.get(0).X;
    int y = results.get(0).Y;
}
cpp
var ola = com("OlaPlug.OlaSoft")
// 0,0,0,0 表示绑定窗口整个客户区
var results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 0,0,0,0 表示绑定窗口整个客户区
results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1)
text
.局部变量 ola, OLAPlug
ola.创建 ()
' 0,0,0,0 表示绑定窗口整个客户区
results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
var results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 0,0,0,0 表示绑定窗口整个客户区
MatchDataList results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 0,0,0,0 表示绑定窗口整个客户区
auto results = ola.MatchWindowsThresholdFromPathAll(0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1);
if (!results.empty() && results[0].MatchState) {
    int32_t x = results[0].X;
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long ptr = MatchWindowsThresholdFromPathAll(instance, 0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1);
if (ptr != 0) {
    char json[8192] = {0};
    GetStringFromPtr(ptr, json, sizeof(json));
    int matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
    double matchVal = 0, angle = 0;
    ParseMatchImageAllJson(instance, json, 0, &matchState, &x, &y, &width, &height, &matchVal, &angle, &index);
    FreeStringPtr(instance, ptr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long MatchWindowsThresholdFromPathAll(long ola, int x1, int y1, int x2, int y2, string colorJson, string templ, double matchVal, double angle, double scale);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int ParseMatchImageAllJson(string str, int parseIndex, out int matchState, out int x, out int y, out int width, out int height, out double matchVal, out double angle, out int index);

long instance = CreateCOLAPlugInterFace();
long ptr = MatchWindowsThresholdFromPathAll(instance, 0, 0, 0, 0, "[{\"StartColor\":\"000000\",\"EndColor\":\"FFFFFF\"}]", "img/template.bmp", 0.9, 0, 1);
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    ParseMatchImageAllJson(sb.ToString(), 0, out int matchState, out int x, out int y, out int w, out int h, out double mv, out double ang, out int idx);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.MatchWindowsThresholdFromPathAll(instance, ...)
# 原生返回 JSON 数组指针,用 ParseMatchImageAllJson(instance, json, 0, ...) 取第一项

返回值

字符串指针,返回JSON数组格式的匹配结果。DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。

返回数据格式:

json
[{
    "MatchVal": 0.85,
    "MatchState": true,
    "Index": 0,
    "Angle": 45.0,
    "X": 100,
    "Y": 200,
    "Width": 100,
    "Height": 100
}]
字段名类型说明
MatchVal浮点数匹配相似度。
MatchState布尔是否匹配成功。
Index整数结果索引(从 0 开始)。
Angle浮点数匹配角度。
X整数X 坐标。
Y整数Y 坐标。
Width整数宽度。
Height整数高度。

注意事项

  • x1、y1、x2、y2都传0时,将搜索整个窗口客户区
  • 返回的坐标是相对于绑定窗口客户区的坐标